<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>后台登录</title>
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/login.css" />
</head>

<body>
<div class="m-login-bg">
  <div class="m-login">
    <h3>后台系统登录</h3>
    <div class="m-login-warp">
      <form class="layui-form" method="post" action="{:url()}">
        <div class="layui-form-item">
          <input type="text" name="username" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
          <input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
          <div class="layui-inline">
            <input type="text" name="passcode" required lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input">
          </div>
          <div class="layui-inline"> <img class="verifyImg" onclick="javascript:$(this).attr('src',conv_url('{:captcha_src()}')+Math.random());" src="{:captcha_src()}" /> </div>
        </div>
		  <div id="iptext" class="layui-form-item" style="padding-top: 10px;color: #FF0000;display:none;">
		  </div>
        <div class="layui-form-item m-login-btn">
          <div class="layui-inline">
            <button class="layui-btn layui-btn-normal login_btn" lay-submit lay-filter="login">登录</button>
          </div>
          <div class="layui-inline">
            <!--<button type="reset" class="layui-btn layui-btn-primary">取消</button>-->
          </div>
        </div>
      </form>
    </div>
    <p class="copyright">Copyright 2015-2018 by xiaocui</p>
  </div>
</div>
<script src="__STATIC__/js/jquery.min.js" type="text/javascript" charset="utf-8"></script> 
<script src="__STATIC__/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script> 
<script src="__STATIC__/js/common.js" type="text/javascript" charset="utf-8"></script> 
<script>
	$.get("{:url('admin/publics/ipajax')}", function(result){
		if (result=="1"){
			$("#iptext").html("你的IP为空，不允许登录，清联系管理员");
			$("#iptext").show();
		}else if (result=="2"){
			$("#iptext").html("你的IP不允许登录，清联系管理员");
			$("#iptext").show();
		}else{
			$("#iptext").hiden();
		}
	});

			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form(),
					layer = layui.layer;


				//自定义验证规则
				form.verify({
					title: function(value) {
						if(value.length < 5) {
							return '用户名至少得5个字符！';
						}
					},
					password: [/(.+){6,12}$/, '密码必须6到12位！'],
					verity: [/(.+){4}$/, '验证码必须是4位！'],
					
				});

				
				//监听提交
				form.on('submit(login)', function(pdata) {
					$('.login_btn').attr('disabled',true);
					$.ajax({
						url:$('.layui-form').attr('action'),
						data:pdata.field,
						type:'POST',
						success: function(data){
							if(data.code==1){
								layer.msg(data.msg);
								var timer = setInterval(function(){
									clearInterval(timer);
									window.top.location.href=data.url;	
								},2000);	
							}else{
								layer.msg(data.msg);	
								$('.login_btn').attr('disabled',false);
								$('.verifyImg').click();
							}
						}
					});
					
					/*layer.alert(JSON.stringify(data.field), {
						title: '最终的提交信息'
					})*/
					return false;
				});

			});
		</script>
</body>
</html>